package com.qilin.hammer;

import static com.qilin.hammer.util.Global.ORCLE_DATABASE;

import java.sql.Connection;
import java.util.*;

import com.qilin.hammer.util.database.*;

public class DBHelper {

	public static void CreateMultiTypeEventData(int size){
		DBFactory dbfactory = new DBFactory();
    	DBConnection orclconnector = dbfactory.getDBConnectionInstance(ORCLE_DATABASE);
    	Connection orclconn = orclconnector.getConnection("10.111.3.50", "1521", "ZHANGRM", "123456");
    	DBOperator orcloperator = new DBOperator(orclconn);
    	orcloperator.execute("delete from multitypedata");
    	Random r=new Random(47);
		byte bytes[]={Byte.MAX_VALUE,Byte.MIN_VALUE};
		short shorts[]={Short.MAX_VALUE,Short.MIN_VALUE};
		int ints[]={Integer.MAX_VALUE,Integer.MIN_VALUE};
		long longs[]={Long.MAX_VALUE,Long.MIN_VALUE};

		float floats[]={Float.MAX_VALUE,Float.MIN_VALUE};
		String str="hello world";
		String types[] = {"first", "second", "third"};
    	for(int i=0;i<size;i++){
    		int p=i%2;
    		String sql="insert into multitypedata values ";
    		str = types[r.nextInt(types.length)];
    		sql+="("+(i+1)+",'"+str+"',"+(p==0?"'true'":"'false'")+","+bytes[p]+","+shorts[p]+","+ints[p]+","
    					+longs[p]+","+r.nextDouble()*10000+","+floats[p]+",sysdate,sysdate,sysdate,"
    					+"'db"+str+"','"+str+"')";
    		System.out.println(sql);
    		orcloperator.execute(sql);
    		//insert into multitypedata values (1,'Correct',1,127,32767,2147483647,9223372036854775807,0,3.4028235E38,to_date('2011-11-12 12:12:12','yyyy-MM-dd hh24:mi:ss'),to_date('21-08-2003','DD-MM-YYYY'),to_date('21-08-2003','DD-MM-YYYY'),'hello world','hello world')
    	}
	} 
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		DBHelper.CreateMultiTypeEventData(50);
	}

}
